/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.gar.bc;

import edu.upn.sigemfi.gar.be.Notaria;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;

/**
 *
 * @author Freddy
 */
@Stateless
public class NotariaFacade implements NotariaFacadeLocal {
    @PersistenceContext
    private EntityManager em;

    public void create(Notaria notaria) {
        em.persist(notaria);
    }

    public void edit(Notaria notaria) {
        em.merge(notaria);
    }

    public void remove(Notaria notaria) {
        em.remove(em.merge(notaria));
    }

    public Notaria find(Object id) {
        return em.find(Notaria.class, id);
    }

    public List<Notaria> findAll() {
        return em.createQuery("select object(o) from Notaria as o").getResultList();
    }

    public Notaria findById(Long codigo) {
        return Notaria.class.cast(em.createQuery("select object(o) from Notaria as o where o.idNotaria ="+codigo.toString()).getSingleResult());
    }

}
